package file;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Exercise {
    public static void main(String[] args) throws IOException {
        for (int i = 1; i < 11; i++) {
            File file = new File("./document" + i + ".exe");
            if (file.exists()) {
                System.out.println("文件已存在");
            } else {
                file.createNewFile();
                System.out.println("document" + i + "创建完成");
            }
        }
        File directory = new File("./");
        if (directory.isDirectory()) {
            File[] subs = directory.listFiles(pathname -> pathname.getName().endsWith(".exe"));
            for (File sub : subs) {
                System.out.println(sub.getName());
            }
        }
        File file = new File("./document9.exe");
        System.out.println("documeng9文件的文件名是" + file.getName());//document9.exe
        System.out.println("directory文件是目录吗：" + directory.isDirectory());//true
        System.out.println("存在directory文件或目录吗：" + directory.exists());//true
        if (directory.isDirectory()) {
            File[] subs = directory.listFiles(pathname -> pathname.getName().endsWith(".exe"));
            System.out.println("后缀是.exe的文件有：");
            for (File sub : subs) {
                System.out.println(sub.getName());
            }
        }
        System.out.println("file的名字是：" + file.getName());//document9.exe
        System.out.println("file的大小是：" + file.length());//0
        System.out.println("file是否为隐藏文件：" + file.isHidden());//f
        System.out.println("file是否为可读：" + file.canRead());//t
        System.out.println("file是否为可写：" + file.canWrite());//t
        System.out.println("file是否已存在：" + file.exists());//t
        File w = new File("./tedu.png");
        if (w.exists()) {
            System.out.println("存在");
        } else {
            w.createNewFile();//Png
            System.out.println("创建完成");
        }
        File directory1 = new File("./directory/a/232/546");
        if (directory.isDirectory()) {
            directory1.mkdirs();
        }
        directory1.delete();//只能删除路径最后空目录
    }
}
